PHP面试题-字符串处理
weixin_39804852:
[code=php]
function camecase1($str){
$temp_arr = explode('-',$str); // array
$temp_str = '';
foreach( $temp_arr as $val) {
$temp_str .= ucfirst($val);
}
return lcfirst($temp_str);
}
function camecase2($str){
$temp_arr = explode('-',$str); // array
for ($i=1; $i < count($temp_arr); $i++) {
$temp_arr[$i] = ucfirst($temp_arr[$i]);
}
return implode('',$temp_arr);
}
function camecase3($str){
$temp_str = '';
$token = strtok($str,'-');
while ($token !== false) {
$temp_str .= ucfirst($token);
$token = strtok('-');
}
return lcfirst($temp_str);
}
[/code]
|